#include "qmylabel.h"

#include "../../include/abstractproperty.h"
#include "../../include/qcommonstruct.h"
#include "../../lib/shared/qdatamanager.h"

#include <QVariant>
#include <QMouseEvent>

QLabelHost::QLabelHost(QWidget *wid):
    QObjectHost(wid)
{

}

QString QLabelHost::text()
{
    return ((QLabel*)m_widget)->text();
}

QMyLabel::QMyLabel(QWidget *parent):
    QLabel(parent),
    m_host(new QLabelHost(this))
{
    setProperty("className","QLabel");
    setProperty("typeName","label");
    setProperty("typeIcon",":/images/widgets/label.png");
    setText("");
    setProperty("objectName","label");


    m_host->addProperty("Attribute",QStringList()<<"font"<<"focusPolicy"<<"text"<<"margin"<<"wordWrap");
    m_host->addProperty("StyleSheet",QStringList()<<"color"<<"textColor"<<"image"<<"padding");
    m_host->addUserProperty(QStringList()<<"text");
}

void QMyLabel::updateProperty(const QString & name)
{
    if(name=="Z-Value")
    {
        emit zValueChanged();
    }
    m_host->updateStyle(name);
}

void QMyLabel::updatePropertyAttribute()
{
    m_host->updatePropertyAttribute();
}

void QMyLabel::initProperty()
{
    if(property("running").toBool())
    {
        m_host->setGlobalObject(sender());
        m_host->initRunningProperty();
    }
}



QLCDNumberHost::QLCDNumberHost(QWidget *wid):
    QObjectHost(wid)
{

}

double QLCDNumberHost::value()
{
    return ((QLCDNumber*)m_widget)->value();
}

QMyLCDNumber::QMyLCDNumber(QWidget *parent):
    QLCDNumber(parent),
    m_host(new QLCDNumberHost(this))
{
    setProperty("className","QLCDNumber");
    setProperty("typeName","LCD Number");
    setProperty("typeIcon",":/images/widgets/lcdnumber.png");
    display(0);

    m_host->addProperty("Attribute",QStringList()<<"font"<<"focusPolicy"<<"value"<<"mode"<<"numDigits");
    m_host->addProperty("StyleSheet",QStringList()<<"color"<<"image");
    m_host->addUserProperty(QStringList()<<"value");
}

void QMyLCDNumber::updateProperty(const QString & name)
{
    if(name=="Z-Value")
    {
        emit zValueChanged();
    }
    m_host->updateStyle(name);
}

void QMyLCDNumber::updatePropertyAttribute()
{
    m_host->updatePropertyAttribute();
}

void QMyLCDNumber::initProperty()
{
    if(property("running").toBool())
    {
        m_host->setGlobalObject(sender());
        m_host->initRunningProperty();
    }
}
